package tutorial.lite_mod.vote_tool;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import public_util.model.Const4PublicDataBase;
import public_util.model.PublicMiddleTable;
import public_util.model.ReturnData;
import system_api_4_trade.dao.ApiPublicMiddleTableMapper;
import system_api_4_trade.util.sql.SelectTool;
import system_api_4_trade.util.tool_4_handle.StringToolApi;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 这个类用来提供给before和after方法使用,用于MiddleTable的返回
 */
public class TemplateUtilApi {

    private static Logger logger = Logger.getLogger(TemplateUtilApi.class);






    /**
     * 验证链接: duzikai_api_mgr_public_middle_table?invoke_method=public_load_middle_table_list&pre_db_para_middle_table_name=public_middle_table_lite_mod_vote_tool&type_middle_app=102001&type_inner_app=1001&mid_table_remark_009=1&&pre_cmd_para_show_option_data=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_option_data(List<PublicMiddleTable> tbList, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);
        String pre_cmd_para_show_option_data = request.getParameter("pre_cmd_para_show_option_data");
        if ("true".equals(pre_cmd_para_show_option_data))
        {
            for (int i = 0; i < tbList.size(); i++)
            {
                PublicMiddleTable subArrangeData = tbList.get(i);
                int id_public_mid_table = subArrangeData.getId_public_middle_table();//ID
                if (id_public_mid_table <= 0)
                {
                    logger.error("没有设置mid_table_remark_020的信息");
                    continue;
                }
                int type_middle_app = subArrangeData.getType_middle_app();
                int type_inner_app = subArrangeData.getType_inner_app();
                if (type_middle_app == 102001 && type_inner_app == 1001)
                {
                    HashMap<String, Object> search015 = new HashMap<>();
                    search015.put(Const4PublicDataBase.PARA_mid_table_remark_013+ "_in", id_public_mid_table);
                    search015.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 103001);
                    search015.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                    search015.put("is_online", "0");
                    HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(search015, "public_middle_table_lite_mod_vote_tool");
                    List<PublicMiddleTable> dianzanAll = middleTableMapper.tableDataList(realPara);// 周期的配置
                    int dianzan_num = 0;
                    if (dianzanAll != null)
                    {
                        dianzan_num = dianzanAll.size();
                    }
                    subArrangeData.setSave_data_001(dianzan_num);
                }
            }

        }
        return null;
    }


    /**
     * 验证链接: duzikai_api_mgr_public_middle_table?invoke_method=public_load_middle_table_list&pre_db_para_middle_table_name=public_middle_table_lite_mod_vote_tool&type_middle_app=103001&type_inner_app=1001&pre_db_para_group_by_para=id_public_user_info&mid_table_remark_009=1&mid_table_remark_013=&pre_cmd_para_show_user_data=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_user_data(List<PublicMiddleTable> tbList, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);
        String pre_cmd_para_show_user_data = request.getParameter("pre_cmd_para_show_user_data");
        if ("true".equals(pre_cmd_para_show_user_data))
        {
            for (int i = 0; i < tbList.size(); i++)
            {
                PublicMiddleTable subArrangeData = tbList.get(i);
                int id_public_mid_table = subArrangeData.getId_public_middle_table();//ID
                if (id_public_mid_table <= 0)
                {
                    logger.error("没有设置mid_table_remark_0的信息");
                    continue;
                }
                int type_middle_app = subArrangeData.getType_middle_app();
                int type_inner_app = subArrangeData.getType_inner_app();
                int id_public_user_info = subArrangeData.getId_public_user_info();
                String mid_table_remark_013 = request.getParameter("mid_table_remark_013");
                String mid_table_remark_009 = request.getParameter("mid_table_remark_009");
                mid_table_remark_013 = StringToolApi.paraHttpFilter(mid_table_remark_013);
                mid_table_remark_009 = StringToolApi.paraHttpFilter(mid_table_remark_009);
                if (type_middle_app == 103001 && type_inner_app == 1001)
                {
                    HashMap<String, Object> search015 = new HashMap<>();
                    if (mid_table_remark_013 != null)
                    {
                        search015.put(Const4PublicDataBase.PARA_mid_table_remark_013+ "_in", id_public_mid_table);
                    }
                    search015.put(Const4PublicDataBase.PARA_type_middle_app+ "_in", 103001);
                    search015.put(Const4PublicDataBase.PARA_type_inner_app+ "_in", 1001);
                    search015.put(Const4PublicDataBase.PARA_id_public_user_info + "_in", id_public_user_info);
                    search015.put(Const4PublicDataBase.PARA_mid_table_remark_009 + "_in", mid_table_remark_009);
                    search015.put("is_online", "0");
                    HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(search015, "public_middle_table_lite_mod_vote_tool");
                    List<PublicMiddleTable> dianzanAll = middleTableMapper.tableDataList(realPara);// 周期的配置
                    int dianzan_num = 0;
                    if (dianzanAll != null)
                    {
                        dianzan_num = dianzanAll.size();
                    }
                    subArrangeData.setSave_data_001(dianzan_num);
                }
            }

        }
        return null;
    }


}
